#ifndef  _FLAPP_RS485_H_
#define  _FLAPP_RS485_H_
#include <stdint.h>

#define RS_485_TX_EN 								GPIOA->scr = GPIO_PINS_4	//485发送使能
#define RS_485_RX_EN 								GPIOA->clr = GPIO_PINS_4	//485接收使能

#define DEFAULT_RS485_HEAD1		0xA5
#define DEFAULT_RS485_HEAD2		0x5A
#define ADDR_SLAVE_COUNT			10		//连续访问7次还是从机的话定义为从机

typedef enum
{
	DEVICE_UNKNOWN 					= 0,					//未知设备
	DEVICE_MASTER,												//设备做主机
	DEVICE_SLAVE,													//设备做从机
}flapp_device_type_e;

typedef enum
{
	ICON_AUTO 					= 0,					
	ICON_ION,													
	ICON_FILTER,											
	ICON_NET,
}flapp_rs485_icon_e;

typedef enum 							//主机发送从机接收
{
  RS485_MOSI_HEAD_H						=0,	//0xA55A
	RS485_MOSI_HEAD_L						=1,	
	RS485_MOSI_DEVICE						=2,	
	RS485_MOSI_ADDR							=3, 
	RS485_MOSI_ICON							=4,
	RS485_MOSI_AIR_LEV					=5,
	RS485_MOSI_FAN_SPEED				=6,	
	RS485_MOSI_TEMP_H						=7,	//温度
	RS485_MOSI_TEMP_L						=8,	//温度
	RS485_MOSI_HUM_H						=9,	//湿度
	RS485_MOSI_HUM_L						=10,	//湿度
	RS485_MOSI_PM25_H						=11,//pm2.5
	RS485_MOSI_PM25_L						=12,	
	RS485_MOSI_VOC_H						=13,//voc
	RS485_MOSI_VOC_L						=14,	
	RS485_MOSI_RES1							=15,
	RS485_MOSI_RES2							=16,
	RS485_MOSI_CHECKNUM					=17,//校验码
	RS485_MOSI_ENUM_END,
}flapp_rs485_mosi_e;

typedef enum 							//主机接收从机发送
{
  RS485_MISO_HEAD_H						=0,	//0xAA
	RS485_MISO_HEAD_L						=1,	
	RS485_MISO_DEVICE						=2,
	RS485_MISO_ADDR							=3,
	RS485_MISO_ERR							=4,	
	RS485_MISO_RES1							=5,	
	RS485_MISO_RES2							=6,	
	RS485_MISO_CHECKNUM					=7,//校验码
	RS485_MISO_ENUM_END
}flapp_rs485_miso_e;

void flapp_485_init(void);
void flapp_is_485_master(void);
void flapp_rs485_run(void);
flapp_device_type_e flapp_get_device_type(void);
#endif

